package myproject.CarRentalSystem;

import java.util.Scanner;

public class CarRentalTest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        CarRental carRental = new CarRental("金路至尊租赁有限公司", "5663245");
        System.out.println(carRental.getName()+"欢迎您，请致电"+carRental.getPhone()+"洽谈相关租赁业务！");
        while (true) {
            System.out.println("1:查看车辆信息  2:租车  3:还车 4:报废 5:买新车 6:查看租赁记录 7:查看收入");
            System.out.print("请选择：(输入0退出)");
            int choose = in.nextInt();
            if (choose == 1) {
                carRental.showCarInfo();
            } else if (choose == 2) {
                int no2 = 0;
                System.out.println("您想要租什么车：1、轿车 2、客车");
                while (true) {
                    System.out.print("请选择：");
                    no2 = in.nextInt();
                    if (no2 != 1 && no2 != 2) {
                        System.out.println("数字无效，重新输入");
                    } else {
                        break;
                    }
                }
                carRental.show(no2);
                System.out.print("请输入车牌号：");
                String plate = in.next();
                Car car = carRental.rentCar(no2, plate);
                if (car == null) {
                    System.out.println("租车失败");
                    continue;
                }
                System.out.print("您想要租几天？");
                int day = in.nextInt();
                System.out.print("提供您的姓名：");
                String name = in.next();
                System.out.print("提供您的手机号：");
                String phone = in.next();
                Customer customer = new Customer(name, phone, car.getPlate(), day);
                carRental.record(customer);
                float money = car.rentMoney(day);
                carRental.earnMoney(money);
                System.out.println("租车成功，请支付" + money + "元，您租用的车辆信息：");
                System.out.println(car.toString());

            } else if (choose == 3) {
                //还车
                System.out.print("请输入准被还车的车牌号：");
                String plate = in.next();
                int no3 = carRental.rebackCar(plate);
                if (no3 == 1) {
                    System.out.println(plate + "这辆车并未被租用");
                } else if (no3 == 2) {
                    System.out.println(plate + "还车成功");
                } else if (no3 == 3) {
                    System.out.println(plate + "不存在，请输入正确的车牌");
                }
            } else if (choose == 4) {
                //报废
                System.out.println("所有车辆信息：");
                carRental.showCarInfo();
                System.out.print("输入想要报废的车的车牌号：");
                String plate = in.next();
                int no4 = carRental.scrap(plate);
                if (no4 == 1) {
                    System.out.println(plate + "这辆车不存在");
                } else if (no4 == 2) {
                    System.out.println(plate + "这辆车被租出去了，不可以报废");
                } else if (no4 == 3) {
                    System.out.println(plate + "这辆车报废成功");
                }

            } else if (choose == 5) {
                System.out.println("购买 1.轿车 2.客车");
                while (true) {
                    System.out.print("请选择：");
                    int no = in.nextInt();
                    if (no == 1) {
                        Saloon saloon = new Saloon();
                        System.out.print("品牌：");
                        saloon.setBrand(in.next());
                        System.out.print("车辆型号：");
                        saloon.setKind(in.next());
                        System.out.print("车牌号：");
                        saloon.setPlate(in.next());
                        System.out.print("日租金：");
                        saloon.setDayOfMoney(in.nextInt());
                        carRental.buyCar(saloon);
                        System.out.println("购买成功");
                        break;
                    } else if (no == 2) {
                        Bus bus = new Bus();
                        System.out.print("品牌：");
                        bus.setBrand(in.next());
                        System.out.print("输入座位数：");
                        bus.setSeat(in.nextInt());
                        System.out.print("车牌号：");
                        bus.setPlate(in.next());
                        System.out.print("日租金：");
                        bus.setDayOfMoney(in.nextInt());
                        carRental.buyCar(bus);
                        System.out.println("购买成功");
                        break;
                    } else {
                        System.out.println("数字无效，重新选择");
                    }
                }
            } else if (choose == 6) {
                //查看租赁记录
                System.out.println("租赁记录：");
                carRental.showRecord();

            } else if (choose == 7) {
                System.out.println("收入");
                System.out.println(carRental.getMoney() + "元");
            } else if (choose == 0) {
                break;
            }
        }
    }
}
